package org.wu.framework.log.platform.application.impl;

import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.log.platform.application.RunLogApplication;
import org.wu.framework.web.response.Result;
import org.wu.framework.log.platform.domain.model.run.log.RunLog;
import org.wu.framework.log.platform.application.command.run.log.RunLogRemoveCommand;
import org.wu.framework.log.platform.application.command.run.log.RunLogStoryCommand;
import org.wu.framework.log.platform.application.command.run.log.RunLogUpdateCommand;
import org.wu.framework.log.platform.application.command.run.log.RunLogQueryListCommand;
import org.wu.framework.log.platform.application.command.run.log.RunLogQueryOneCommand;
import org.wu.framework.log.platform.application.assembler.RunLogDTOAssembler;
import org.wu.framework.log.platform.application.dto.RunLogDTO;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;
import org.wu.framework.log.platform.domain.model.run.log.RunLogRepository;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe 运行日志 
 *
 * @author Jia wei Wu
 * @date 2024/03/24 01:02 下午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class RunLogApplicationImpl implements RunLogApplication {

    @Resource
    RunLogRepository runLogRepository;
    /**
     * describe 新增运行日志
     *
     * @param runLogStoryCommand 新增运行日志     
     * @return {@link Result<RunLog>} 运行日志新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLog> story(RunLogStoryCommand runLogStoryCommand) {
        RunLog runLog = RunLogDTOAssembler.INSTANCE.toRunLog(runLogStoryCommand);
        return runLogRepository.story(runLog);
    }
    /**
     * describe 批量新增运行日志
     *
     * @param runLogStoryCommandList 批量新增运行日志     
     * @return {@link Result<List<RunLog>>} 运行日志新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<List<RunLog>> batchStory(List<RunLogStoryCommand> runLogStoryCommandList) {
        List<RunLog> runLogList = runLogStoryCommandList.stream().map( RunLogDTOAssembler.INSTANCE::toRunLog).collect(Collectors.toList());
        return runLogRepository.batchStory(runLogList);
    }
    /**
     * describe 更新运行日志
     *
     * @param runLogUpdateCommand 更新运行日志     
     * @return {@link Result<RunLog>} 运行日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLog> updateOne(RunLogUpdateCommand runLogUpdateCommand) {
        RunLog runLog = RunLogDTOAssembler.INSTANCE.toRunLog(runLogUpdateCommand);
        return runLogRepository.story(runLog);
    }

    /**
     * describe 查询单个运行日志
     *
     * @param runLogQueryOneCommand 查询单个运行日志     
     * @return {@link Result<RunLogDTO>} 运行日志DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLogDTO> findOne(RunLogQueryOneCommand runLogQueryOneCommand) {
        RunLog runLog = RunLogDTOAssembler.INSTANCE.toRunLog(runLogQueryOneCommand);
        return runLogRepository.findOne(runLog).convert(RunLogDTOAssembler.INSTANCE::fromRunLog);
    }

    /**
     * describe 查询多个运行日志
     *
     * @param runLogQueryListCommand 查询多个运行日志     
     * @return {@link Result<List<RunLogDTO>>} 运行日志DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<List<RunLogDTO>> findList(RunLogQueryListCommand runLogQueryListCommand) {
        RunLog runLog = RunLogDTOAssembler.INSTANCE.toRunLog(runLogQueryListCommand);
        return runLogRepository.findList(runLog)        .convert(runLogs -> runLogs.stream().map(RunLogDTOAssembler.INSTANCE::fromRunLog).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个运行日志
     *
     * @param runLogQueryListCommand 分页查询多个运行日志     
     * @return {@link Result<LazyPage<RunLogDTO>>} 分页运行日志DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<LazyPage<RunLogDTO>> findPage(int size,int current,RunLogQueryListCommand runLogQueryListCommand) {
        RunLog runLog = RunLogDTOAssembler.INSTANCE.toRunLog(runLogQueryListCommand);
        return runLogRepository.findPage(size,current,runLog)        .convert(page -> page.convert(RunLogDTOAssembler.INSTANCE::fromRunLog))            ;
    }

    /**
     * describe 删除运行日志
     *
     * @param runLogRemoveCommand 删除运行日志     
     * @return {@link Result<RunLog>} 运行日志     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLog> remove(RunLogRemoveCommand runLogRemoveCommand) {
     RunLog runLog = RunLogDTOAssembler.INSTANCE.toRunLog(runLogRemoveCommand);
     return runLogRepository.remove(runLog);
    }

}